package com.asset.admin.system.syemenu.form;

import com.asset.admin.dao.entity.SysMenuEntity;
import com.asset.admin.system.syemenu.enums.EnumEnableStatus;
import com.fasterxml.jackson.annotation.JsonInclude;

import java.util.Map;
import java.util.Objects;

/**
 * <p>
 * todo 描述
 * </p>
 *
 * @author 牧之
 * @date 2024/6/26 21:32
 */
@JsonInclude(JsonInclude.Include.NON_EMPTY)
public class MenuForm {

    private Integer id;
    private Integer pid;
    private String name;
    private String url;
    private String permissions;
    private Integer menuType;
    private String status;
    private String icon;
    private Integer sort;
    private Long creator;
    private String createName;
    private String createDate;
    private Integer updater;
    private String updateDate;

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public Integer getPid() {
        return pid;
    }

    public void setPid(Integer pid) {
        this.pid = pid;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public String getPermissions() {
        return permissions;
    }

    public void setPermissions(String permissions) {
        this.permissions = permissions;
    }

    public Integer getMenuType() {
        return menuType;
    }

    public void setMenuType(Integer menuType) {
        this.menuType = menuType;
    }

    public String getIcon() {
        return icon;
    }

    public void setIcon(String icon) {
        this.icon = icon;
    }

    public Integer getSort() {
        return sort;
    }

    public void setSort(Integer sort) {
        this.sort = sort;
    }

    public Long getCreator() {
        return creator;
    }

    public void setCreator(Long creator) {
        this.creator = creator;
    }

    public String getCreateDate() {
        return createDate;
    }

    public void setCreateDate(String createDate) {
        this.createDate = createDate;
    }

    public Integer getUpdater() {
        return updater;
    }

    public void setUpdater(Integer updater) {
        this.updater = updater;
    }

    public String getUpdateDate() {
        return updateDate;
    }

    public void setUpdateDate(String updateDate) {
        this.updateDate = updateDate;
    }


    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    public String getCreateName() {
        return createName;
    }

    public void setCreateName(String createName) {
        this.createName = createName;
    }

    public static MenuForm convert2MenuForm(SysMenuEntity entity, Map<Long, String> userIdNameMap){
        MenuForm form = new MenuForm();
        if(entity == null){
            return form;
        }
        form.setId(entity.getId());
        form.setPid(entity.getPid());
        form.setName(entity.getName());
        form.setUrl(entity.getUrl());
        form.setPermissions(entity.getPermissions());
        form.setMenuType(entity.getMenuType());
        form.setIcon(entity.getIcon());
        form.setSort(entity.getSort());
        form.setCreator(entity.getCreator());
        form.setCreateName(userIdNameMap == null ? "" : userIdNameMap.get(entity.getCreator()));
        form.setCreateDate(entity.getCreateDate());
        form.setUpdater(entity.getUpdater());
        form.setUpdateDate(entity.getUpdateDate());
        form.setStatus(Objects.requireNonNull(EnumEnableStatus.getEnumByCode(entity.getStatus())).getValue());
        return form;
    }
}
